<template>
  <div class="content-block">
    <div class="content-main">
      <div class="content-title">
        <div class="title-text-dot">企业审核</div>
        <div class="title-handle">
          <div class="handel-item">
            <el-button type="primary" size="mini" @click="handleSearch"
            >查 询
            </el-button
            >
          </div>
          <div class="handel-item">
            <el-input v-model="wuqTitle" size="mini" type="text" placeholder="企业名称"></el-input>
          </div>
        </div>
      </div>
      <el-table
          :data="companyList"
          border
          size="mini"
          height="calc(100vh - 230px)"
          v-loading="tableLoading"
          style="width: 100%"
      >
        <el-table-column
            type="index"
            label="序号"
            :index="indexMethod"
            align="center"
            width="50"
        ></el-table-column>
        <el-table-column label="企业名称" prop="wuqTitle"></el-table-column>
        <el-table-column label="法人" prop="wuqName"></el-table-column>
        <el-table-column label="手机号" prop="wuqPhone"></el-table-column>
        <el-table-column label="地址" prop="wuqArea"></el-table-column>
        <el-table-column label="余额" prop="balance">
          <template slot-scope="scope">
            <span>{{ formatMoney(scope.row.balance) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="wuqStatus">
          <template slot-scope="scope">
            <span>{{ scope.row.wuqStatus | wuqStatusName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button
                size="mini"
                type="text"
                title="详情"
                class="text-orange"
                @click="audit(scope.row)"
            >详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-size="pageSize"
          :page-sizes="[5, 10, 20, 50]"
          layout="total, sizes, prev, pager, next"
          :total="total"
      ></el-pagination>
    </div>

    <el-dialog
        title="审核意见"
        :visible.sync="dialogVisible"
        width="30%"
    >
      <div>
        <el-form>
          <el-form-item>
            <el-input placeholder="请输入审核意见" v-model="formAuth"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible = false">取 消</el-button>
        <el-button size="small" type="danger" @click="rejected"
        >驳 回</el-button
        >
        <el-button size="small" type="primary" @click="saveCheckAuth"
        >确 定</el-button
        >
      </span>
    </el-dialog>
    <companyDetail :rowDetail="currentRow" ref="companyDetail"></companyDetail>
  </div>
</template>

<script>
import Api from "../../constants/Api";
import companyDetail from "./components/company-detail"

export default {
  components: {
    companyDetail
  },
  data() {
    return {
      wuqTitle: "",
      formAuth: "",
      arrAtuh: {},
      tableLoading: false,
      companyList: [],
      pageSize: 10,
      pageNum: 1,
      total: 0,
      dialogVisible: false,
      currentRow: {}
    };
  },
  methods: {
    rejected() {
      this.$axios({
        method: 'post',
        url: Api.handler,
        data: {
          wuqId: this.arrAtuh.wuqId,
          wuqOpinion: this.formAuth,
          wuqStatus: this.arrAtuh.wuqStatus
        }
      }).then(res => {
        if (res.code == 20005) {
          this.$message.success("驳回提交")
          this.dialogVisible = false
        } else {
          this.$message.error(res.msg)
        }
      }).catch(() => {
        this.$message.error(res.msg)
      })
    },
    audit(row) {
      this.currentRow = row
      this.$refs['companyDetail'].show()
    },
    saveCheckAuth() {
      this.$axios({
        method: 'post',
        url: Api.handler,
        data: {
          wuqId: this.arrAtuh.wuqId,
          wuqOpinion: this.formAuth,
          wuqStatus: "2"
        }
      }).then(res => {
        if (res.code == 20005) {
          this.$message.success(res.msg)
          this.dialogVisible = false
        } else {
          this.$message.error(res.msg)
        }
      }).catch(() => {
        this.$message.error(res.msg)
      })
    },
    indexMethod(index) {
      return (this.pageNum - 1) * this.pageSize + 1 + index;
    },
    handleSearch() {
      this.$axios({
        method: 'post',
        url: Api.getCompanyList,
        data: {
          current: this.pageNum,
          pageSize: this.pageSize,
          wuqTitle: this.wuqTitle
        }
      }).then(res => {
        this.tableLoading = false;
        this.total = res.data.total;
        this.companyList = res.data.records;
      }).catch(() => {
        this.tableLoading = false
      })
    },
    handleCurrentChange(n) {
      this.pageNum = n;
      this.__init();
    },
    handleSizeChange() {
    },
    init() {
      this.tableLoading = true;
      this.$axios({
        method: 'post',
        url: Api.getCompanyList,
        data: {
          current: this.pageNum,
          pageSize: this.pageSize,
          wuqTitle: this.wuqTitle
        }
      }).then(res => {
        this.tableLoading = false;
        this.total = res.data.total;
        this.companyList = res.data.records;
      }).catch(() => {
        this.tableLoading = false
      })
    },
  },
  created() {
    this.init();
  },
};
</script>

<style>
</style>
